<template>
  <div class="card-wrap">
    <el-form>
      <el-form-item label-width="200px" label="请设置获取1张年卡粉丝数：">
        <el-input v-model="num" type="text" class="num-input"/>
      </el-form-item>
    </el-form>
    <el-row class="row">
      <el-button type="primary" class="btn" @click="handleSubmit">确认</el-button>
    </el-row>
  </div>
</template>
<script>
import { update } from '@/api/data'
export default {
  name: 'BasicCard',
  data() {
    return {
      num: ''
    }
  },
  methods: {
    handleSubmit() {
      const flag = this.check()
      flag ? this.modification() : ''
    },
    check() {
      const price = this.num
      if (price.trim() === '') {
        this.$message.warning({
          duration: 1000,
          message: '价格不能为空'
        })
        return false
      }
      return true
    },
    modification() {
      const name = this.num
      const id = '17'
      update(id, name)
        .then((res) => {
          if (res.success) {
            this.$message.success({
              duration: 1000,
              message: '设置成功'
            })
          }
        }).catch((e) => {
          this.$message.warning({
            duration: 1000,
            message: '请稍后再试'
          })
        })
    }
  }
}
</script>
<style lang="scss" scoped>
.card-wrap {
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
  .num-input {
    width: 200px;
  }
  .row {
    padding-left: 200px;
    box-sizing: border-box;
    .btn {
      width: 200px;
    }
  }
}
</style>
